1
Anatomy of C++ Statements
AI037 Lesson 8
00:00

In C++, the journey from abstract values to execution begins with the statement. An expression statement is created simply by appending a semicolon to an expression, compelling the compiler to evaluate it and progress the flow of control sequentially.

1. The Null Statement

A null statement (;) is a placeholder used when the language requires a statement but your logic does not. While useful in some loops, beware the extraneous null statement—an accidental semicolon after a while or if header can lead to devastating logic errors where the intended body is ignored.

⚠️ Warning (p. 235): An accidental semicolon after a loop header creates a null statement as the body, often resulting in infinite loops.

2. Compound Statements (Blocks)

A compound statement, or block, is a sequence of statements enclosed in curly braces { }. It is treated as a single unit of execution. Blocks define their own scope; names defined inside are invisible outside.

Single Statement val = x + y; std::cout << val; Compound Statement (Block) { val = x + y; return val; }
Note (p. 235): Unlike simple statements, a block is not terminated by a semicolon.
main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>